<?php

use Biz\service\Store\CustomCategoryWikiService;
use Doraemon\pockets\constInterface\statSign\AutoModule;
use Doraemon\service\statSign\Basic as basicStatSign;


/**
 * Description: 商品列表
 * Created by IntelliJ IDEA.
 * User: 玉坤
 * Date: 2021/7/29
 * Time: 13:58
 */
class WikiListAction extends ActionPlugin
{
    public const USER_LEVEL = self::LEVEL_NOTHING;
    public const PAGE_SIZE = 20;

    public function main()
    {
        $store_id = $this->getRequest()->getPost('store_id', 0);
        $category_id = $this->getRequest()->getPost('category_id', 0);
        $per_page = $this->getRequest()->getPost('per_page', self::PAGE_SIZE);
        $page = $this->getRequest()->getPost('page', 1);
        if (!$store_id) {
            throw new Exception('非法传参');
        }
        $data = CustomCategoryWikiService::getWikiByStoreId($store_id,(int)$category_id, (int)$per_page, (int)$page);
        if ($data['list']) {
            foreach ($data['list'] as &$item) {
                $item['statSign'] = basicStatSign::genStatSign(AutoModule::MODULE_STORE_SEC_PAGE_WIKI_LIST, [],
                    ['wiki_id' => $item['id'], 'store_id' => $store_id, 'act_from' => 'store_sec_page']);
            }
        }
        $data['list']= \Doraemon\tools\StatSign::versionCompatible($data['list'], \Doraemon\tools\StatSign::BRAND_UP_GRADE_VERSION_521, \Doraemon\tools\BlockType::TYPE_WIKI, 'wiki');

        $this->setSuccess($data);
    }
}